package com.cxy.controller.admin;

import com.cxy.dto.SeeTaskDTO;
import com.cxy.dto.TaskInsertDTO;
import com.cxy.dto.UpdateTaskDTO;
import com.cxy.entity.Task;
import com.cxy.result.Result;
import com.cxy.service.TaskService;
import com.cxy.vo.TaskCompleteVO;
import com.cxy.vo.TaskNoRelease;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "任务相关业务功能")
@RestController
@RequestMapping("/task")
@Slf4j
public class TaskController {
    @Autowired
    private TaskService taskService;
    /**
     * 添加任务
     */
    @ApiOperation("添加任务")
    @PostMapping("/insert")
    public Result insert(@RequestBody TaskInsertDTO taskInsertDTO){
        log.info("添加任务:{}",taskInsertDTO);
        taskService.insert(taskInsertDTO);
        return Result.success();
    }
    /**
     * 查看任务(待发布)
     */
    @ApiOperation("查看任务(待发布)")
    @GetMapping("/select/TaskNoRelease")
    public Result<List<TaskNoRelease>> seeTaskNoRelease(SeeTaskDTO seeTaskDTO){
        List<TaskNoRelease>taskNo = taskService.seeTaskNoRelease(seeTaskDTO);
        return Result.success(taskNo);
    }
    /**
     * 修改任务期数
     */
    @ApiOperation("修改任务期数")
    @PutMapping("/update")
    public Result updateTask(@RequestBody UpdateTaskDTO updateTaskDTO){
        log.info("修改的信息:{}",updateTaskDTO);
        taskService.updateTask(updateTaskDTO);
        return Result.success();
    }
    /**
     * 根据id查询任务期数
     */
    @ApiOperation("根据id查询任务期数")
    @GetMapping("/select/{id}")
    public Result<String> getById(@PathVariable Long id){
        log.info("要查修的数据id:{}",id);
        String dateNumber =taskService.getById(id);
        return Result.success(dateNumber);
    }
    /**
     * 发布任务
     */
    @ApiOperation("发布任务")
    @PutMapping("/taskRelease")
    public Result taskRelease(Long id){
        taskService.taskRelease(id);
        return Result.success();
    }
    /**
     * 查询任务（进行中）
     */
    @ApiOperation("查询任务（进行中）")
    @GetMapping("/select/selectTaskComplete")
    public Result<TaskCompleteVO> selectTaskComplete( SeeTaskDTO seeTaskDTO){
        log.info("查询条件");
        TaskCompleteVO taskCompleteVO = taskService.selectTaskComplete(seeTaskDTO);
        return Result.success(taskCompleteVO);
    }
    /**
     * 删除任务
     */
    @ApiOperation("删除任务")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        taskService.delete(id);
        return Result.success();
    }
    /**
     * 结束任务
     */
    @ApiOperation("结束任务")
    @PutMapping("/overTask")
    public Result overTask(Long id){
        log.info("结束任务id:{}",id);
        taskService.overTask(id);
        return Result.success();
    }
}
